<template>
  <div :id="id" style="width: 80vw; height: 300px"></div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  props: {
    id: {
      type: String,
      require: true
    },
    xdata: {
      type: Array,
      require: true
    },
    ydata: {
      type: Array,
      require: true
    }
  },
  mounted() {
    // 操作DOM  获取DOM元素 写在mounted组件挂载完毕
    var chartDom = document.getElementById(this.id)
    // 初始化echarts
    var myChart = echarts.init(chartDom)
    /*** 配置项开始 */
    var option

    option = {
      title: {
        text: '7日销售图',
        x: 'center',
        top: '20'
      },
      // 横向数据配置
      xAxis: {
        type: 'category',
        data: this.xdata
      },
      // 竖向数据
      yAxis: {
        type: 'value'
      },
      // 对应数据的值
      series: [
        {
          data: this.ydata,
          // 图表类型
          type: 'bar',
          color: '#ff0000'
        }
      ]
    }
    option && myChart.setOption(option)
    /**** 图表配置项结束   设置配置项生效 */
  }
}
</script>

<style lang="scss" scoped>
</style>